/**
 * Created by ChrisBi on 16/7/24.
 */
//audio left
function PlayAudioLeft(idx){
    var voice = document.getElementById("voice" + idx);
    var img = document.getElementById("PlayPause" + idx);
    img.onclick = function(){
        if (voice.paused){
            voice.play();
        } else{
            voice.pause();
        }
    }
    voice.addEventListener("play", function (e) {
        img.src = "icon/voice_left_click.gif";
    }, false);
    voice.addEventListener("pause", function (e) {
        img.src = "icon/voice_left.png";
    }, false);

}


//audio right
function PlayAudioRight(idx){
    var voiceR = document.getElementById("voiceMe" + idx);
    var imgR = document.getElementById("PlayPauseMe" + idx);
    imgR.onclick = function(){
        if (voiceR.paused){
            voiceR.play();
        } else{
            voiceR.pause();
        }
    }
    voiceR.addEventListener("play", function (e) {
        imgR.src = "icon/voice_right_click.gif";
    }, false);
    voiceR.addEventListener("pause", function (e) {
        imgR.src = "icon/voice_right.png";
    }, false);
}

/**
 * Created by Rison on 22/5/4.
 */
var MsgDef = {
    text:1,                 //文字
    normalImg: 2,           //图片
    video:4,                //视频
    link:5,                 //链接
    gps:6,                  //位置消息
    file:8,                 //文件
    chatHistory:14,         //聊天记录
    contact:16,             //名片
    innerChatHistory:17,    //聊天记录-嵌套
    wechatNote:18,          //笔记
    miniProgram:19,         //小程序
    shipinhao:20,           //视频号
};

var WeChat = {
    isTextMsg:      function(item) {
        return item.m_uiMessageType === MsgDef.text;
    },
    isEmojiMsg:     function(item) {
        return false;
    },
    getEmojiUrl:    function(item) {
        return "";
    },
    isImageMsg:     function(item) {
        return item.m_uiMessageType === MsgDef.normalImg;
    },
    isVoiceMsg:     function(item) {
        return false;
    },
    isVideoMsg:     function(item) {
        return item.m_uiMessageType === MsgDef.video;
    },
    isVideoChat:    function(item) {
        return false;
    },
    isFileMsg:      function(item) {
        return item.m_uiMessageType === MsgDef.file;
    },
    isShareLink:    function(item) {
        let t = item.m_uiMessageType;
        return t===MsgDef.link || t===MsgDef.chatHistory || t===MsgDef.innerChatHistory || t===MsgDef.wechatNote;
    },
    isLocationMsg:  function(item) {
        return item.m_uiMessageType === MsgDef.gps;
    },
    isContactMsg:   function(item) {
        return item.m_uiMessageType == MsgDef.contact;
    },
    isMiniProgram:  function(item) {
        return item.m_uiMessageType === MsgDef.miniProgram;
    },

    getHeaderImage: function(item) {
        let has_header = item.from && item.from.head;
        return has_header ? item.from.head : "img/wechat/person.jpg";
    },
    getLinkThumbnail: function(item) {
        return item.m_nsThumbnail ? 'background-image: url('+item.m_nsThumbnail+');' : '';
    }
};